# Maintainer: Andrew Chadwick <a.t.chadwick@gmail.com>

_realname=styrene
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
conflicts=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
replaces=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
pkgver=0.3.0
pkgrel=3
pkgdesc="Repacks MSYS2 packages into installer .exes and standalone .zips (mingw-w64)"
url="https://github.com/achadwick/styrene"
arch=('any')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
makedepends=('git')
depends=("zip"
         "${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-gcc"
         "${MINGW_PACKAGE_PREFIX}-binutils"
         "${MINGW_PACKAGE_PREFIX}-nsis")
license=('GPLv3+')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/achadwick/styrene/archive/v${pkgver}.tar.gz)
sha256sums=('5b31beb1ee0fcb6518fe83eb1933b539a0583feae4b0eda942cb497101e3f6a4')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  rm -rf build
  python3 setup.py build
}

package() {
  cd "${srcdir}"/${_realname}-${pkgver}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install \
    --prefix="${MINGW_PREFIX}" \
    --root="${pkgdir}"

  # De-hardcode script paths
  local MINGW_PREFIX_W=$(cygpath -m "${MINGW_PREFIX}")
  sed -i -e "s,${MINGW_PREFIX_W},${MINGW_PREFIX},g" \
      "${pkgdir}${MINGW_PREFIX}/bin/styrene"

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/COPYING
}
